package cn.walls1717.wallsmall.product.web;

import cn.walls1717.wallsmall.product.entity.CategoryEntity;
import cn.walls1717.wallsmall.product.service.CategoryService;
import cn.walls1717.wallsmall.product.vo.Catelog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 首页
 *
 * @author walls1717
 * @since 2022/11/02 21:02
 **/
@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    /** 初始化商城首页 */
    @GetMapping({"/", "/index.html"})
    public String indexPage(Model model) {
        List<CategoryEntity> categories = categoryService.listOneLevelCategories();
        model.addAttribute("categories", categories);
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }

}
